package com.ag.lwc.action;

import java.util.List;
import com.ag.bean.TbEvent;
import com.ag.bean.TbTarget;
import com.ag.common.BaseAction;
import com.ag.dao.TbEventDAO;
import com.ag.lwc.service.TargetService;

public class TargetAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1509785333794374238L;
	private TbTarget target;			//事件影响范围
	private List<TbTarget> result;
	private String message;
	private TargetService service;
	private TbEvent event;								//事件，从session中获取
	private TbEventDAO eventDAO;						//测试用的事件dao
	public void setEventDAO(TbEventDAO eventDAO) {
		this.eventDAO = eventDAO;
	}
	public String find()
	{
	event=this.getEvent();
		System.out.println(event.getEId());
		result=service.find(event.getEId());
		System.out.println("*********action:******防控目标列表的长度："+result.size());
		message="findSuccess";
		return "find";
	}
	public String delete()
	{
		try
		{
			service.delete(target.getTId());
			message="delete_success";	
		}
		catch(Exception e)
		{
			message="删除失败:"+e.toString();		
		}
		return "delete";
	}
	public String save()
	{
		event=this.getEvent();
		target.setTbEvent(event);
		try
		{
			System.out.println("******************事件编号："+target.getTbEvent().getEId());
			service.save(target);
			message="save_success";
			
		}
		catch(Exception e)
		{
			message="保存失败:"+e.toString();
			System.out.println("**********************"+message+"***************************");
		}
		return "save";
	}
	public String modify()
	{
		event=this.getEvent();
		target.setTbEvent(event);
		try
		{
			service.update(target);
			message="change_success";		
		}
		catch(Exception e)
		{
			message="修改失败:"+e.toString();
			
		}
		return "modify";
	}
	public TbTarget getTarget() {
		return target;
	}
	public void setTarget(TbTarget target) {
		this.target = target;
	}
	public List<TbTarget> getResult() {
		return result;
	}
	public void setResult(List<TbTarget> result) {
		this.result = result;
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	public TargetService getService() {
		return service;
	}
	public void setService(TargetService service) {
		this.service = service;
	}
	public TbEvent getEvent() {
		event = eventDAO.findById("1009181001");
		System.out.println("**************action: 输出事件名称："+event.getEEventname()+"*******************");
	
		return event;
	}
	public void setEvent(TbEvent event) {
		this.event = event;
	}

}
